package day9;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

/**
 * @author oldliu
 * @since 1.0
 */
public class TalkClient {
    public static void main(String[] args) {
        try {
            Socket s=new Socket("192.168.1.131",9999);
            InputStream in = s.getInputStream();
            OutputStream out = s.getOutputStream();
            BufferedReader br=new BufferedReader(new InputStreamReader(in));
            PrintWriter pw=new PrintWriter(out,true);
            Scanner sc=new Scanner(System.in);
            System.out.println("和服务端建立了链接："+s);
            while (true){
                System.out.println("想说啥：");
                String str=sc.next();
                pw.println(str);
                String reply=br.readLine();
                System.out.println("服务器回复:"+reply);
                if(str.equals("exit"))
                    break;
            }
            System.out.println("聊天结束了。。。");
            s.close();//问题
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
